package cn.est.controller;

import cn.est.pojo.Users;
import cn.est.utils.RedisUtil;
import cn.est.utils.SMSUtil;
import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName TestController
 * @Description TODO
 * @Author yaozhaobao
 * @Date 2021/3/31 8:55
 * @Version 1.0
 **/
@RestController
@RequestMapping("/test")
public class TestController {


    @Autowired
    RedisUtil redisUtil;

    @Autowired
    SMSUtil smsUtil;


    @RequestMapping(value = "/setredis",method = RequestMethod.POST)
    public Object setRedis(){
        Users users =new Users();
        users.setUserName("周杰伦");
        users.setAccount("111");
        redisUtil.set("zhoujielun",users);
        return  "创建用户成功";
    }

    @RequestMapping(value = "/getredis",method = RequestMethod.GET)
    public Object getRedis(){
     Users users = (Users) redisUtil.get("zhoujielun");
        return  users;
    }



    @ApiOperation(value="过去所有用户", notes="获取所有的用户信息",httpMethod = "GET")
    @RequestMapping(value="allusers", method= RequestMethod.GET)
    public Object getAllUser(){

        return "所有的用户信息";
    }



    @ApiOperation(value="根据用户id获取用户信息", notes="获取所有的用户信息",httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "用户ID", required = true, dataType = "int")
    })
    @RequestMapping(value="/userbyid", method= RequestMethod.GET)
    public Object getUserById(@RequestParam(required =true,value = "id") Integer id){

        return "获取uid="+id+"用户信息";
    }


    @RequestMapping(value="/sendsms", method= RequestMethod.GET)
    public Object sentMsg(){

        SendSmsResponse response=null;
        try {
         response= smsUtil.sendSms("18814120272","{code:12345}");
            return "发送短信成功"+response.body.getCode();
        } catch (Exception e) {
            e.printStackTrace();
        }

        return "发送短信失败"+response.body.getCode();
    }













}
